package com.cgbl.cg.view

import android.content.Context
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.cg.R
import com.cgbl.cg.adapter.CollectPopAdapter
import com.lxj.xpopup.core.BottomPopupView
import com.robot.base.model.CollectDetailBean

class WorkCollectPop(context: Context, var list: MutableList<CollectDetailBean>) :
    BottomPopupView(context) {

    private var confirmClickListener: (id: String) -> Unit = {}

    private var rightClickListener: () -> Unit = {}

    private lateinit var tvAdd: TextView
    private lateinit var tvConfirm: TextView
    private lateinit var mRvCollect: RecyclerView
    private lateinit var collectPopAdapter: CollectPopAdapter

    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_work_collect
    }

    override fun initPopupContent() {
        super.initPopupContent()
        tvAdd = findViewById(R.id.tv_add)
        tvConfirm = findViewById(R.id.tv_confirm)
        mRvCollect = findViewById(R.id.mRv_collect)

        collectPopAdapter = CollectPopAdapter()
        mRvCollect.adapter = collectPopAdapter
        collectPopAdapter.setNewInstance(list)

        tvAdd.setOnClickListener {
            rightClickListener.invoke()
        }

        tvConfirm.setOnClickListener {
            if (collectPopAdapter.selectPosition != -1)
                confirmClickListener.invoke(
                    collectPopAdapter.data[collectPopAdapter.selectPosition].collectId ?: ""
                )
        }
    }

    fun setConfirmClickListener(click: (id: String) -> Unit): WorkCollectPop {
        confirmClickListener = click
        return this
    }

    fun setRightClickListener(click: () -> Unit): WorkCollectPop {
        rightClickListener = click
        return this
    }
}